﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yu.Cms.Common;

namespace Yu.Cms.Web.UserCtrl.Default
{
    public partial class Archive : BaseCtrl
    {
        private static int BigID = 0;
        private static int SmlID = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BigID = YuRequest.GetInt("BigID", 0);
                SmlID = YuRequest.GetInt("SmlID", 0);
                this.OnStart();
            }
        }

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="BigID"></param>
        /// <param name="SmlID"></param>
        protected void OnStart()
        {
            this.ShowNavi();
            this.BindList();
         
        }

        /// <summary>
        /// 显示导航
        /// </summary>
        /// <param name="BigID"></param>
        /// <param name="SmlID"></param>
        protected void ShowNavi()
        {
            int bid;
            string title = string.Empty;
            if (SmlID != 0)
            {
                Yu.Cms.Model.SmallType mSmallType = bllSmallType.GetModel(SmlID);
                lblNav.Text = mSmallType.SmallTypeName;
                bid = mSmallType.BigTypeID;
                Yu.Cms.Model.BigType mBigType = bllBigType.GetModel(bid);
                hlNav.NavigateUrl = "/Category.aspx?BigID=" + mBigType.BigTypeID;
                title= hlNav.Text = mBigType.BigTypeName;
                lblchar.Text = "&raquo;";                
            }
            else
            {
                if (BigID != 0)
                {
                    Yu.Cms.Model.BigType mBigType = bllBigType.GetModel(BigID);
                    title= lblNav.Text = mBigType.BigTypeName;
                }
            }
            (base.Page.Master.FindControl("lblTitle") as Literal).Text = title;
        }

        protected void BindList()
        {
            int RecordCount=0;
            if (SmlID != 0)
            {
                rpt.DataSource = bllContent.GetListBySmallType(SmlID, Pager.CurrentPageIndex, Pager.PageSize, out RecordCount);
            }
            else
            {
                if (BigID != 0)
                {
                    rpt.DataSource = bllContent.GetListByBigType(BigID, Pager.CurrentPageIndex, Pager.PageSize, out RecordCount);
                }
            }
            rpt.DataBind();
            Pager.RecordCount = RecordCount;
        }

        protected void Pager_PageChanged(object sender, EventArgs e)
        {
            this.BindList();
        }
        
    }
}